<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of shippingcom
 *
 * @author hassanali
 */
class statues extends admin_controller {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model('admin/statues_model');
    }

    public function index() {
        $falid_id = $this->statues_model->is_id('statues');

        $data['count'] = count($falid_id);
        $data['result'] = $this->statues_model->filter();
        $data['pagination'] = $this->admin_pagination('index', count($this->statues_model->filter(true)), 10);
        $this->themes->render('statues/index', $data);
    }

    public function view() {

        $id = get_segment(4);
        $falid_id = $this->statues_model->is_id('statues', array('id' => $id), 'statues/');
        $data['result'] = $falid_id;


       
        $this->themes->render('statues/view', $data);
    }

    public function edit() {
        // start function login 

        $id = get_segment(4);
        $id_id = $this->statues_model->is_id('statues', array('id' => $id));
        $data['shippingcom'] = $id_id;
        $validation = array(
            array(
                'field' => 'title',
                'label' => lang('label_title'),
                'rules' => 'required|trim'
            )
        );

        $this->form_validation->set_rules($validation);

        if ($this->form_validation->run() == FALSE) {


            $this->themes->render('statues/edit', $data);
        } else {


            $user_data['title'] = $this->input->post('title');

            $user_data = $this->statues_model->update($user_data,$id);
            $this->themes->set_message(array('url' => 'statues/', 'type' => 'success', 'message' => 'message_edit_success'));
        }
    }

    public function add() {

        $validation = array(
            array(
                'field' => 'title',
                'label' => lang('label_title'),
                'rules' => 'required|trim'
            )
        );

        $this->form_validation->set_rules($validation);

        if ($this->form_validation->run() == FALSE) {
            $this->themes->render('statues/add');
        } else {

            $user_data['title'] = $this->input->post('title');
            $user_data['user_id'] = $this->admin_id;

            $user_data = $this->statues_model->save($user_data);

            $this->themes->set_message(array('url' => 'statues/', 'type' => 'success', 'message' => 'message_add_success'));
        }
    }

    public function all() {
        $id = $this->input->post('id');
        $doaction = $this->input->post('doaction');
        // valid if no item select 
        $this->empty_id_actionall($id);
        $this->empty_id_actionall($doaction, 'message_select_action_from_dropdown');

        switch ($doaction) {
            case 'default': {

                    $data['default'] = 'YES';
                    $this->statues_model->update_all($id, $data);
                    $this->themes->set_message(array('url' => 'statues/', 'type' => 'success', 'message' => 'message_edit_success'));
                }
                break;
            case 'undefault': {

                    $data['default'] = 'NO';
                    $this->statues_model->update_all($id, $data);
                    $this->themes->set_message(array('url' => 'statues/', 'type' => 'success', 'message' => 'message_edit_success'));
                }
                break;
            case 'delete': {
                    
                    $this->statues_model->delete($id);
                    $this->themes->set_message(array('url' => 'statues/', 'type' => 'success', 'message' => 'message_edit_success'));
                }
                break;

            default:

                break;
        }
       
    }

    public function delete() {
        $id = get_segment(4);
        
        $falid_id = $this->statues_model->is_id('statues', array('id' => $id), 'statues/');
        
        $this->statues_model->delete($id);

        $this->themes->set_message(array('url' => 'statues/', 'type' => 'success', 'message' => 'message_delete_success'));
    }

}

?>
